package com.southwind.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.southwind.entity.TbAdmin;
import com.southwind.form.RuleForm;
import com.southwind.mapper.TbAdminMapper;
import com.southwind.service.TbAdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.southwind.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fjh
 * @since 2024-01-08
 */
@Service
public class TbAdminServiceImpl extends ServiceImpl<TbAdminMapper, TbAdmin> implements TbAdminService {
    @Autowired
    private TbAdminMapper tbAdminMapper;

    @Override
    public ResultVO login(RuleForm ruleForm) {
        /*1,判断用户是否存在*/
        QueryWrapper<TbAdmin> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("username",ruleForm.getUsername());
        TbAdmin tbAdmin= this.tbAdminMapper.selectOne(queryWrapper);
        ResultVO resultVO=new ResultVO();
        if (tbAdmin==null){
            resultVO.setCode(-1);
        }else {
            /**2,判断密码是否正确*/
            if(!tbAdmin.getPassword().equals(ruleForm.getPassword())){
                resultVO.setCode(-2);
            }else {
                resultVO.setCode(0);
                resultVO.setData(tbAdmin);
            }
        }
        return resultVO;
    }
}
